package com.zjt.service.user;

import com.zjt.dao.user.IFeedBackDao;
import com.zjt.entity.FeedBack;
import com.zjt.utils.DateUtil;
import com.zjt.web.api.vo.base.PageVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 物码中心数据采集的DAO interface;
 * 
 * @author xueyanbeijing
 */
@Component
public class FeedBackService implements IFeedBackService {
    private static Logger logger = LoggerFactory.getLogger(ClientUserService.class);
    private IFeedBackDao feedBackDao;
    @Autowired
    public void setFeedBackDao(IFeedBackDao feedBackDao) {
        this.feedBackDao = feedBackDao;
    }

    @Override
    public boolean saveFeedBack(long userId, String email, String content) {
        try
        {
            FeedBack feedBack = new FeedBack();
            feedBack.setContent(content);
            feedBack.setUserId(userId);
            feedBack.setEmail(email);
            feedBack.setCreateDate(DateUtil.getCurrentDate());
            feedBack.setUpdateDate(DateUtil.getCurrentDate());
            feedBack.setEnableFlag("Y");
            feedBack.setStatus(0);//0 1
            this.feedBackDao.save(feedBack);
            return true;

        }catch (Exception e){
            return false;
        }
          //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public List<FeedBack> getFeedBackListByUserId(long userId) {
        return this.feedBackDao.findByUserId(userId);  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public int countFeedBackByUserId(long userId) {
        return (int)this.feedBackDao.count();  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public Page<FeedBack> getFeedBackList(PageVO pageVO) {
        PageRequest pageRequest = new PageRequest(pageVO.getPageNo(),pageVO.getPageSize());
        Page<FeedBack> pageList = null;
        pageList = this.feedBackDao.findAll(pageRequest);
        return pageList;  //To change body of implemented methods use File | Settings | File Templates.
    }
}
